/* -*- c++ -*-
    Copyright (C) 2007 Vladimir Shabanov <vshabanoff@gmail.com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
#ifndef __OSGCAL__MESH_DISPLAY_LISTS_H__
#define __OSGCAL__MESH_DISPLAY_LISTS_H__

#include <osg/Drawable>

#include <osgCal/Export>
#include <osgCal/MeshData>

namespace osgCal
{

    /**
     * Mesh geometry display lists. Display lists are created
     * one per \c CoreMesh, not per \c Model's \c Mesh
     */
    struct OSGCAL_EXPORT MeshDisplayLists : public osg::Referenced
    {
        public:
            typedef osg::buffered_value< GLuint > GLObjectList;

            /**
             * Hardware mesh display lists, once compiled for
             * one model they are shared for all core model
             * instances.
             */
            mutable GLObjectList        lists;
            mutable OpenThreads::Mutex  mutex;

            /**
             * Destroys display lists.
             */
            ~MeshDisplayLists();

            /**
             * Check that display lists are compiled for all
             * contexts and free mesh data that is needed only
             * for display lists (normals, tangents, texture
             * coordinates).
             *
             * Use
             * osg::DisplaySettings::instance()->setMaxNumberOfGraphicsContexts(N)
             * to set number of contexts you need (default
             * value is 32, so no mesh data or textures are
             * freed by default).
             */
            void checkAllDisplayListsCompiled( MeshData* data ) const;

            virtual void releaseGLObjects( osg::State* state = 0 ) const;

    };

}; // namespace osgCal

#endif
